import React, { useEffect, useState } from "react";
import actions from "../qiankun/actions";

function Home() {
	const [username, setUsername ] = useState("");
	useEffect(() => {
		// 子应用监听actions数据
		actions.onGlobalStateChange(state => {
			console.log("React子应用", state)
			setUsername(state.username);
		}, true)
	}, [])

	const changeState = () => {
		// 修改全局的状态
		actions.setGlobalState({username: "feitianmaotai"+parseInt(Math.random()*1000)})
	}
	return (
		<div>
			<h1>sub-react-demo-home</h1>
			<h3>{ username }</h3>
			<button onClick={changeState}>修改</button>
		</div>
	);
}

export default Home;